# -*- coding: utf-8 -*-
# @File : test.py
# @Time : 2024/5/21 13:29
# @Author : syq
# @Email : 1721169065@qq.com
# @Software: PyCharm



from playwright.sync_api import Playwright, sync_playwright
def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    page.goto("F:\pycharmGit\playwrightStudy\练习iframe\index.html")
    page.wait_for_timeout(2000)
    # 操作非 iframe上的元素
    page.locator('[id="maininput"]').fill("I am a index page's div!")
    # 操作 iframe 上的元素
    frame = page.frame_locator("iframe[id^=frameA]")
    # xpath 匹配
    frame.locator('[id="iframeinput"]').fill('This is a iframe input!')
    page.wait_for_timeout(3000)
    # page.pause()
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)

